/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.component.comboBox;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.plaf.basic.BasicComboPopup;

import com.ruipengkj.bean.TExePos;
import com.ruipengkj.commons.util.Util;
import com.ruipengkj.component.JComboBoxPOJO;
import com.ruipengkj.component.jdialog.BorderJPanel;
import com.ruipengkj.view.orderView.desk.DeskPanel;
import com.ruipengkj.view.orderView.desk.DeskTypePanel;
/**
 * 桌子下拉内容可设置高度的JComboBox  -----  list
 */
public class JComboBoxPopupDesk extends BasicComboPopup {
	private static final long serialVersionUID = 1L;
	
	private JComboBox box;
	
	private DeskTypePanel typePanel;// 餐桌类型 面板
	private DeskPanel deskPanel;// 餐桌面板
	
	public JComboBoxPopupDesk(JComboBox box) {
		super(box);
		this.box = box;
		init();
	}

	private void init() {
		typePanel = new DeskTypePanel() {
			private static final long serialVersionUID = 1L;
			@Override
			// 查询菜品
			public void QueryDesk(String CatalogId) {
				deskPanel.byTypeQueryDesk(CatalogId);
			}
			
			@Override
			protected void setNoDesk() {
				TExePos TExePos = new TExePos();
				TExePos.setName("没有餐桌");
				
				box.removeAllItems();
				box.addItem(new JComboBoxPOJO(null, TExePos.getName(), null));
				box.setSelectedIndex(0);
				JComboBoxPopupDesk.super.hide();
			}
		};

		deskPanel = new DeskPanel() {
			private static final long serialVersionUID = 1L;
			@Override
			//点击桌子后的回调函数
			public void AddDesk(TExePos TExePos) {
				box.removeAllItems();
				box.addItem(new JComboBoxPOJO(TExePos.getPosID(),TExePos.getName(), TExePos));
				box.setSelectedIndex(0);
				JComboBoxPopupDesk.super.hide();
			}
		};

		deskPanel.setButtonGroup(typePanel.getNoDeskButton());
		
		JPanel mainPanel = new BorderJPanel(new BorderLayout()) {
			private static final long serialVersionUID = 1L;

			@Override
			protected void paintComponent(Graphics g) {
				super.paintComponent(g);
				g.setColor(new Color(234, 99, 0));
				g.drawRect(0, 0, this.getWidth() - 1, this.getHeight() - 1);
			}
		};
		
		mainPanel.setBackground(Color.white);
		deskPanel.setOpaque(false);
		typePanel.setOpaque(false);
		mainPanel.add(typePanel, BorderLayout.NORTH);
		mainPanel.add(deskPanel, BorderLayout.CENTER);
		mainPanel.setCursor(Util.CURSOR_DEFAULT);
		
		Util.setSize(mainPanel, 600, 400);
		this.setLayout(new BorderLayout());
		this.add(mainPanel);
	}

	@Override
	protected void firePropertyChange(String propertyName, Object oldValue,Object newValue) {
		if (propertyName.equals("visible")) {
			if (oldValue.equals(Boolean.FALSE)&& newValue.equals(Boolean.TRUE)) { // SHOW
				try {
					typePanel.termQuery();
					deskPanel.byTypeQueryDesk(null);
					deskPanel.setButtonGroup(typePanel.getNoDeskButton());
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			} else if (oldValue.equals(Boolean.TRUE)&& newValue.equals(Boolean.FALSE)) { // HIDE
			}
		}
		super.firePropertyChange(propertyName, oldValue, newValue);
	}
	
	@Override
	public void hide(){
		
	}
}